package com.glodon.paas.document.storage.web.extend.spring;

import java.util.Collections;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.http.MediaType;
import org.springframework.web.servlet.view.ContentNegotiatingViewResolver;


public class NoViewContentNegotiatingViewResolver extends ContentNegotiatingViewResolver {
    private MediaType defaultContentType;

    @Override
    protected List<MediaType> getMediaTypes(HttpServletRequest request) {
        if (request.getAttribute(NoViewAnnotationMethodHandlerAdapter.NO_VIEW) != null)
            return Collections.singletonList(defaultContentType);
        else
            return super.getMediaTypes(request);
    }

    @Override
    public void setDefaultContentType(MediaType defaultContentType) {
        this.defaultContentType = defaultContentType;
    }

    public MediaType getDefaultContentType() {
        return defaultContentType;
    }
}
